# 斐波那契数列
def fib(n):
    if n < 2:
        return n
    else:
        return fib(n-2) + fib(n -1)


# 快排
def quick(qlist):
    if len(qlist) == 0:
        return qlist
    else:
        qb = qlist[0]
        qa = quick([m for m in qlist[1:] if m < qb])
        qc = quick([l for l in qlist[1:] if l >= qb])
        return qa + [qb] + qc


# 随机排序
def insertSort(list):
    for i in range(1, len(list)):
       key = list[i]
       j = i -1
       while j >= 0 and key < list[j]:
           list[j + 1] = list[j]
           j -= 1
           list[j + 1] = key
    return list


# 99乘法表
def n_n():
    for i in range(1, 10):
        for j in range(1, i + 1):
            print(f'{j} * {i} = {j * i} ', end=' ')
        print('\t')
    return "99乘法表"




# 统计字符串中出现次数最多的字符和次数
def strNum(s):
    l1 = {}
    for i in s:
        if i not in l1:
            l1[i] = 1
        else:
            l1[i] += 1
    for k, v in l1.items():
        if v == max(l1.values()):
            return f'字符串：{s},字符：{k}出现最多：{v}次'


# Switch语句
def s():
    d1 = {"a": 1, "b": 2, "c": 3, "d": 4, "e": 5,}
    userInt = "c"
    return d1[userInt]




# map()映射方法
def mamap(l2):
    return  list((map(lambda x: x * 8, l2)))

# 获取list索引位置
def listM():
    l = [34, 45, 12, 344,2]
    return l.index(12)

# 判断字符串中大写的几个，小写的几个
def strEr(s1):
    num_islower = 0
    num_isupper = 0
    for i in s1:
        if i.islower():
            num_islower += 1
        elif i.isupper():
            num_isupper += 1
        else:
            print("您输入的字符串中存在非正常类型！")
    print(f"大写的字母有{num_isupper}个")
    print(f"小写的字母有{num_islower}个")
    return num_isupper, num_islower

# 修改元组内部元素不可修改
def tuple_1(t):
    print("修改之前的的元素是：", t, id(t))
    t[0][1] = 15
    print("修改完的元素是：", t, id(t))


if __name__ == '__main__':
    # 快排调用
    print(quick([34, 2, 65, 12, 1, 24]))

    # 斐波那契数列调用
    print(fib(7))

    # 插入快排调用
    print("插入快排调用", insertSort([435, 2, 36, 31, 78]))

    # 九九乘法表调用
    print(n_n())

    # 调用统计字符串最高次数
    print(strNum("asdasda"))

    # switch语句调用
    print(s())

    # map()映射调用
    print(mamap([2, 3, 4, 55]))

    # list元素的游标位置
    print("list的元素位置：", listM())

    # 大小写字符有多少个
    print(strEr("sadASDdadDASD"))

    # 修改元组中，可修改的元素值
    print(tuple_1(([13,13], 3)))

    # //、%、**的含义
    print(9 //4) # 取除数
    print(9 % 4)  # 取余数
    print(2 ** 4)  #2的4次方

    numbers = [1, 2, 3, 4, 5]
    print(numbers.remove(2))
    print("remove:", numbers)
    del numbers[1]
    print(numbers)
    print(numbers.pop())
    print(set(numbers), tuple(numbers))

    # lambda 匿名函数
    la = lambda x: x * x
    print(la(6))
    a = [1, 2, 3]
    aa = a.__iter__()
    print(aa.__next__())
    print(aa.__next__())

    print(filter(la,a).__iter__())
    print(filter(la,a).__next__())
